#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/6/27
# @Author  : LiJun
# @Email   : lijun@tianyancha.com
# @Version : 1.0.0

import time

from selenium_0627.po_page.add_member_page import AddMemberPage
from selenium_0627.po_page.add_part_page import AddParPage
from selenium_0627.po_page.base_page import BasePage
import allure


class ContactPage(BasePage):

    # 点击 添加成员
    def click_add_member(self):
        time.sleep(2)
        with allure.step("点击「添加成员」"):
            self.finds(*self.by_maps(self.element["ADD_MEMBER"]))[0].click()

        return AddMemberPage(self.driver, self.element)

    def get_member_list(self):
        time.sleep(2)
        with allure.step("获取成员名字列表"):
            name_list = self.finds(*self.by_maps(self.element["GET_MEMBER_LIST"]))
        return [value.get_attribute("title") for value in name_list]

    def click_add_part(self):
        time.sleep(2)
        with allure.step("点击 根部门"):
            self.finds(*self.by_maps(self.element["CLICK_ROOT_PART"]))[0].click()
        with allure.step("点击 「添加部门」"):
            self.find_click(*self.by_maps(self.element["CLICK_PART"]))

        return AddParPage(self.driver, self.element)

    def get_part_name_list(self):
        time.sleep(1)
        with allure.step("获取部门名字列表"):
            name_list = self.finds(*self.by_maps(self.element["PART_NAME_LIST"]))
        print(f"部门列表:{len(name_list)}")

        return [value.text for value in name_list]

